<?php
    //echo " Welcome to SK..!!!!"."</br>";
    
    
    paid_course($course_selected);
    
    function paid_course($course_selected ){
        
        $link= array();
        $link[0]="http://www.remotecourse.com/";
        $link[1]="http://gogotraining.com/";
        $link[2]="http://pluralsight.com/";
        
        $good_url=array();
        $valid_url = array();
    
        foreach ($link as $sourcelink){
          //  echo "source".$sourcelink."</br>";
        
            $html = file_get_contents($sourcelink);
            $dom_object = new DOMDocument();
            @$dom_object->loadHTML($html);
            $xpath_node = new DOMXPath($dom_object);
            $a_tag = $xpath_node->query("/html/body//a");
                foreach ( $a_tag as $tag){
        
                    $tag_value = $tag->nodeValue ;

                    //echo $tag_value."</br>";
        
                    $course= "|\b$course_selected\b|i";
        
                        if(preg_match($course,$tag_value)) {
            
                            $url = $tag->getAttribute('href');
                            $start = substr($url, 0, 1);
                            if($start=='h'){
                                $good_url[]=$url;
                                //echo "http url".$url."</br>";
                            }
                            else {
                                $domain = substr($sourcelink, 0, -1);
                                // echo "domain".$domain."</br>";
                                $url_name = $domain.$url;
                                $good_url[]=$url_name;
                                //echo "other url".$url_name."</br>";
                            }
    
                        }
            
                }
        }
        
        //echo "Valid Urls" ."</br>";
        
        foreach ( $good_url as $url){
            
            $remove = strpos($url,'podcasts');
            if ($remove==false){
                if (validate($url,$course_selected)==true){
                $valid_url[]=$url;
                    //echo "url :".$url."</br>";

                    preg_match( '@^(?:http://)?([^/]+)@i', $url, $matches );
                    $host = $matches[1];
                    preg_match('/[^.]+\.[^.]+$/', $host, $matches);
                    $domain = $matches[0];
                    //echo "domain :".$domain."</br>";
                    
                    $type = "paid";
                    insertIntoDatabase($course_selected,$url,$domain,$type);
                    
                    
                }
            }
            
        }
        
        
        
        
        
       // $print_array= implode("</br>",$valid_url);
      //  echo $print_array;
        
        
        }
    
    
?>


